package com.ymatou.iapi.liveseller.testcase;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.ActivityProductDto;
import com.ymatou.iapi.liveseller.parameter.AuditLiveBean;
import com.ymatou.iapi.liveseller.parameter.CreateLiveActivityBean;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.liveseller.parameter.LiveActivityDto;
import com.ymatou.iapi.liveseller.service.AuditLiveCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;
/**
*直播审核通过
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_AuditLive{
	private static AuditLiveBean auditliveBean;
	private static AuditLiveCall auditliveCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("直播审核通过");
	}

	@Before
	public void caseUp() {
		auditliveBean=new AuditLiveBean();
		auditliveCall=new AuditLiveCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(auditliveCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AuditLive_001() {
		Logger.start(true,"直播审核通过,AuditState=1");
		try {
			LiveRoomWapper LiveRoomWapper=new LiveRoomWapper();
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Thread.sleep(1000);
			Integer state1 = LiveRoomWapper.selectLiveRoomById(createlive.getId()).getAuditStatus();
			Logger.verifyEquals(0, state1, "审核前状态");
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			
			auditliveBean.setLiveId(createlive.getId());
			auditliveBean.setAuditState(1);
			auditliveBean.setOperator("aarron");
			auditliveCall.setData(auditliveBean);
			auditliveCall.callService();			
			Logger.verifyEquals("200", auditliveCall.getString("Code"), "验证Code");
			Integer state2 = LiveRoomWapper.selectLiveRoomById(createlive.getId()).getAuditStatus();
			Logger.verifyEquals(1, state2, "审核后状态");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AuditLive_002() {
		Logger.start(true,"直播审核不通过,AuditState=0");
		try {
			LiveRoomWapper LiveRoomWapper=new LiveRoomWapper();
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Thread.sleep(1000);
			Integer state1 = LiveRoomWapper.selectLiveRoomById(createlive.getId()).getAuditStatus();
			Logger.verifyEquals(0, state1, "审核前状态");
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			
			auditliveBean.setLiveId(createlive.getId());
			auditliveBean.setAuditState(0);
			auditliveBean.setOperator("aarron");
			auditliveCall.setData(auditliveBean);
			auditliveCall.callService();			
			Logger.verifyEquals("200", auditliveCall.getString("Code"), "验证Code");
			Integer state2 = LiveRoomWapper.selectLiveRoomById(createlive.getId()).getAuditStatus();
			Logger.verifyEquals(0, state2, "审核后状态");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}